package com.whmnx.my.ui.viewmodel;

import android.app.Application;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;

import com.whmnx.my.BR;
import com.whmnx.my.R;
import com.whmnx.my.ui.adapter.ViewPagerInsideBindingAdapter;
import com.whmnx.my.ui.adapter.ViewPagerJiaoYiBindingAdapter;

import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.binding.command.BindingConsumer;
import me.tatarka.bindingcollectionadapter2.BindingViewPagerAdapter;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
 * author : huang
 * date   : 2020/10/10 0010 18:05
 * version: 1.0
 * @author Administrator
 */
public class JiaoYiModel extends ToolbarViewModel{
    //给ViewPager添加ObservableList
    public ObservableList<ViewPagerItemJiaoYiViewModel> items = new ObservableArrayList<>();

    //给ViewPager添加ItemBinding
    public ItemBinding<ViewPagerItemJiaoYiViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_jiaoyi_viewpager);


    private String[] titles = new String[]{"播豆收购","播豆出售"};

    public JiaoYiModel(@NonNull Application application) {
        super(application);
    }


    public void initToolbar() {
        setTitleText("交易记录");
    }

    public void addPage() {
        items.clear();
        //模拟3个ViewPager页面
        for (int i = 1; i <= titles.length; i++) {
            ViewPagerItemJiaoYiViewModel itemViewModel = new ViewPagerItemJiaoYiViewModel(this,  i);
            items.add(itemViewModel);
        }
    }


    //给ViewPager添加PageTitle
    public final BindingViewPagerAdapter.PageTitles<ViewPagerItemJiaoYiViewModel> pageTitles = new BindingViewPagerAdapter.PageTitles<ViewPagerItemJiaoYiViewModel>() {
        @Override
        public CharSequence getPageTitle(int position, ViewPagerItemJiaoYiViewModel item) {
            return titles[position];
        }
    };
    //给ViewPager添加Adpter，请使用自定义的Adapter继承BindingViewPagerAdapter，重写onBindBinding方法
    public final ViewPagerJiaoYiBindingAdapter adapter = new ViewPagerJiaoYiBindingAdapter();
    //ViewPager切换监听
    public BindingCommand<Integer> onPageSelectedCommand = new BindingCommand<>(new BindingConsumer<Integer>() {
        @Override
        public void call(Integer index) {

        }
    });
}
